
find_quantile <- function(x, y, q, precision) {
  f <- approxfun(x=my.steps, y=estimated.Iecdf, 
                 method = "linear", 
                 yleft=1, 
                 yright=0, 
                 rule = 2, 
                 f = 0, 
                 ties = mean
  )  
  precision <- 0.001
  q <- 1 - q
  v_left <- min(x)
  v_right <- max(x)
  v <- v_left + (v_right - v_left) / 2
  while(abs(f(v) - q) > precision)  {
    if (f(v) - q < 0) v_right <- v
    else v_left <- v
    x <- f(v)
    v <- v_left + (v_right - v_left) / 2  
  }
  v
}

x <- find_quantile(x=my.steps, y=estimated.Iecdf, q=0.95, precision=0.001)